#line 1 "C:/Easypic6/PID [John]/PID [John].c"
typedef struct {

double dState;
double iState;
double iMax, iMin;
double pGain, iGain, dGain;

} SPid;

double UpdatePID(SPid * pid, double error, double position){

 double pTerm, dTerm, iTerm;
 pTerm = pid->pGain * error;
 pid->iState += error;

 if (pid->iState > pid->iMax)
 pid->iState = pid->iMax;
 else if (pid->iState<pid->iMin)
 pid->iState = pid->iMin;

 iTerm = pid->iGain * pid->iState;
 dTerm = pid->dGain * (position - pid->dState);
 pid->dState = position;
 return pTerm + iTerm - dTerm;
}







void main() {

}
